package com.leyou.collect.controller;


import com.leyou.collect.pojo.Collect;
import com.leyou.collect.service.CollectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 购物车控制器
 */
@RestController
public class CollectController {
    @Autowired
    private CollectService collectService;

    /**
     * 收藏商品
     */
    @PostMapping("/addCollect")
    public ResponseEntity<Void> addCollect(@RequestBody Map<String,Object> paraMap){
        collectService.addCollect(paraMap);
        return ResponseEntity.status(HttpStatus.CREATED).build();
    }

    //查询商品是否收藏
    @GetMapping("/checkIsCollect/{id}")
    public ResponseEntity<Boolean> checkIsCollect(@PathVariable Long id){
        Boolean result = collectService.checkIsCollect(id);
        return ResponseEntity.ok(result);
    }


    //取消收藏
    @DeleteMapping("/cancelCollect/{id}")
    public ResponseEntity<Void> cancelCollect(@PathVariable Long id){
        collectService.cancelCollect(id);
        return ResponseEntity.status(HttpStatus.CREATED).build();
    }

    //通过用户id,查询所有收藏商品
    @GetMapping("/findAllCollects")
    public ResponseEntity<List<Collect>> findAllCollects(){
        List<Collect> collects = collectService.findAllCollects();
        return ResponseEntity.ok(collects);
    }

    //通过用户id,查询所有收藏商品
    @GetMapping("/findAllCollects2")
    public ResponseEntity<List<Long>> findAllCollects2(){
        List<Long> skuIds = collectService.findAllCollects2();
        return ResponseEntity.ok(skuIds);
    }

}
